#include "interface/login.h"
#include <QtGui/QApplication>

#include "gps/cusergps.h"

#include "socket/csocketcommunication.h"

#include "mainwindow.h"
#include "interface/login.h"

#include "cbusschedule.h"

#include "QFont"

// client infomation
CUSTOMER_NAME g_customerInfo;

// a define that instrict the length of characters used in protocols.
const int CHARACTERLENGTH = 10;

// the chosen car infomation
CHOSEN_CAR_INFO g_chosenCar;

// the order info
ORDER_INFO g_orderInfo;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // initialize the GPS function
    if (!CUserGPS::InitializeInstance())
    {
        return 0;
    }

    // update every 3 seconds
    CUserGPS::GetInstance()->setUpdateInterval(3000);

    // support for map relative web view
    app.setApplicationName(QString("Chrome"));
    app.setApplicationVersion(QString("1.0"));

    // TODO: read config file to get the configuration

    // initialize the socket engine
    CSocketCommunication::InitInstance();

    // set Ip and port
    CSocketCommunication::setIpAndPort(QString("127.0.0.1"), 6178);

    // connect to server, not until the user exits the system will we close the connection
    CSocketCommunication::GetInstance()->connectToServer();

    // open the login interface
    CMainWindow mainWindow(new interface::CLoginInterface());

    // load xml and form the data structure
    CBusScheduler::InitInstance();
    CBusScheduler::GetInstance()->ReadBusInfoFromXML("busInfo.xml");

    // for chinese input
    QFont font1("unifont",16,50,FALSE);
    qApp->setFont(font1);

    // show out the interface
    mainWindow.show();

    return app.exec();
}
